using System;
using System.Collections;
using Evaluant.Uss;
using NPlot;

namespace NUnit.Performances.Engines
{
	public class PersistenEngineWrite : BaseTest
	{
		private IPersistenceEngine _PersistenceEngine;

		public PersistenEngineWrite()
		{
		}

		public IPersistenceEngine PersistenceEngine
		{
			get { return _PersistenceEngine; }
			set { _PersistenceEngine = value; }
		}

		public override void SetAxis(NPlot.Bitmap.PlotSurface2D surface)
		{
			LinearAxis xaxis = new LinearAxis(0,4);

			surface.XAxis1 = xaxis;

			LogAxis yaxis = new LogAxis(surface.YAxis1);

			yaxis.WorldMin = 0.001f;
			yaxis.WorldMax = 10f;
//			yaxis.LargeTickStep = 1.0f;
			yaxis.Label = "10^time";

			surface.YAxis1 = yaxis;
			surface.YAxis1.Label = "seconds";

		}

		public override double[] Launch() 
		{
			ArrayList result = new ArrayList();
			Counter counter = new Counter();

			foreach(int count in new int[] { 1, 10, 100, 1000, 5000 })
			{

				counter.Start();
				Transaction t = new Transaction();

				for(int i=1; i<= count; i++)
				{
					Entity p1 = new Entity("Person");
					p1.AddValue("Firstname", "Joey");
					p1.AddValue("Lastname", "Triviani");
					p1.AddValue("Age", 32);
					p1.AddValue("Birth", new DateTime(1967, 11, 23));
			
					t.Serialize(p1);
				}

				t.Commit(_PersistenceEngine);
				result.Add(counter.Elapsed().TotalSeconds);
			}

			return (double[])result.ToArray(typeof(double));
		}
	}
}
